{
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "Tce3stUlHN0L"
      },
      "source": [
        "##### Copyright 2018 The TensorFlow Authors.\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "cellView": "form",
        "id": "tuOe1ymfHZPu"
      },
      "outputs": [],
      "source": [
        "#@title Licensed under the Apache License, Version 2.0 (the \"License\");\n",
        "# you may not use this file except in compliance with the License.\n",
        "# You may obtain a copy of the License at\n",
        "#\n",
        "# https://www.apache.org/licenses/LICENSE-2.0\n",
        "#\n",
        "# Unless required by applicable law or agreed to in writing, software\n",
        "# distributed under the License is distributed on an \"AS IS\" BASIS,\n",
        "# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n",
        "# See the License for the specific language governing permissions and\n",
        "# limitations under the License."
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "MfBg1C5NB3X0"
      },
      "source": [
        "# Title\n",
        "\n",
        "_Notebook orignially contributed by: {link to you}_\n",
        "\n",
        "\u003ctable class=\"tfo-notebook-buttons\" align=\"left\"\u003e\n",
        "  \u003ctd\u003e\n",
        "    \u003ca target=\"_blank\" href=\"https://colab.research.google.com/github/tensorflow/examples/blob/master/template/notebook.ipynb\"\u003e\u003cimg src=\"https://www.tensorflow.org/images/colab_logo_32px.png\" /\u003eRun in Google Colab\u003c/a\u003e\n",
        "  \u003c/td\u003e\n",
        "  \u003ctd\u003e\n",
        "    \u003ca target=\"_blank\" href=\"https://github.com/tensorflow/examples/blob/master/template/notebook.ipynb\"\u003e\u003cimg src=\"https://www.tensorflow.org/images/GitHub-Mark-32px.png\" /\u003eView source on GitHub\u003c/a\u003e\n",
        "  \u003c/td\u003e\n",
        "\u003c/table\u003e"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "r6P32iYYV27b"
      },
      "source": [
        "{**Fix these links**}"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "xHxb-dlhMIzW"
      },
      "source": [
        "## Overview\n",
        "\n",
        "{Include a paragraph or two explaining what this example demonstrates, who should be interested in it, and what you need to know before you get started.}\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "MUXex9ctTuDB"
      },
      "source": [
        "## Setup"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "IqR2PQG4ZaZ0"
      },
      "outputs": [],
      "source": [
        "import tensorflow as tf\n",
        "\n",
        "import numpy as np"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "1Eh-iCRVBm0p"
      },
      "source": [
        "{Put all your imports and installs up into a setup section.}"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "UhNtHfuxCGVy"
      },
      "source": [
        "## Notes"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "kKhmFeraTdEI"
      },
      "source": [
        "For general instructions on how to write docs for Tensorflow see [Writing TensorFlow Documentation](https://www.tensorflow.org/community/contribute/docs).\n",
        "\n",
        "The tips below are specific to notebooks for tensorflow."
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "2V22fKegUtF9"
      },
      "source": [
        "### General\n",
        "\n",
        "* Include the collapsed license at the top (this uses Colab's \"Form\" mode to hide the cells).\n",
        "* Only include a single `H1` title.\n",
        "* Include the button-bar immediately under the `H1`.\n",
        "* Include an overview section before any code.\n",
        "* Put all your installs and imports in a setup section.\n",
        "* Always include the three `__future__` imports.\n",
        "* Save the notebook with the Table of Contents open.\n",
        "* Write python3 compatible code.\n",
        "* Keep cells small (~max 20 lines).\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "YrsKXcPRUvK9"
      },
      "source": [
        "### Working in GitHub\n",
        "\n",
        "* Be consistent about how you save your notebooks, otherwise the JSON-diffs will be a mess.\n",
        "\n",
        "* This notebook has the \"Omit code cell output when saving this notebook\" option set. GitHub refuses to diff notebooks with large diffs (inline images).\n",
        "\n",
        "* [reviewnb.com](http://reviewnb.com) may help. You can access it using this bookmarklet:\n",
        "\n",
        "  ```\n",
        "javascript:(function(){ window.open(window.location.toString().replace(/github\\.com/, 'app.reviewnb.com').replace(/files$/,\"\")); })()\n",
        " ```\n",
        " \n",
        "* To open a GitHub notebook in Colab use the [Open in Colab](https://chrome.google.com/webstore/detail/open-in-colab/iogfkhleblhcpcekbiedikdehleodpjo) extension (or make a bookmarklet).\n",
        "  \n",
        "* The easiest way to edit a notebook in GitHub is to open it with Colab from the branch you want to edit. Then use File --\u003e Save a copy in GitHub, which will save it back to the branch you opened it from.\n",
        "\n",
        "* For PRs it's helpful to post a direct Colab link to the PR head: https://colab.research.google.com/github/{user}/{repo}/blob/{branch}/{path}.ipynb\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "QKp40qS-DGEZ"
      },
      "source": [
        "### Code Style\n",
        "\n",
        "\n",
        "* Notebooks are for people. Write code optimized for clarity.\n",
        "\n",
        "* Demonstrate small parts before combining them into something more complex. Like below:"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "KtylpxOmceaC"
      },
      "outputs": [],
      "source": [
        "#Build the model\n",
        "model = tf.keras.Sequential([\n",
        "    tf.keras.layers.Dense(10, activation='relu', input_shape=(None, 5)),\n",
        "    tf.keras.layers.Dense(3)\n",
        "])"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "mMOeXVmbdilM"
      },
      "outputs": [],
      "source": [
        "# Run the model on a single batch of data, and inspect the output.\n",
        "result = model(tf.constant(np.random.randn(10,5), dtype = tf.float32)).numpy()\n",
        "\n",
        "print(\"min:\", result.min())\n",
        "print(\"max:\", result.max())\n",
        "print(\"mean:\", result.mean())\n",
        "print(\"shape:\", result.shape)"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "U82B_tH2d294"
      },
      "outputs": [],
      "source": [
        "# Compile the model for training\n",
        "model.compile(optimizer=tf.keras.optimizers.Adam(),\n",
        "              loss=tf.keras.losses.CategoricalCrossentropy(from_logits=True))"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "g3-lzxbCZi-H"
      },
      "source": [
        "* Keep examples quick. Use small datasets, or small slices of datasets. You don't need to train to convergence, train until it's obvious it's making progress.\n",
        "\n",
        "* For a large example, don't try to fit all the code in the notebook. Add python files to tensorflow examples, and in the noptebook run: `!pip install git+https://github.com/tensorflow/examples`"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "TJdqBNBbS78n"
      },
      "source": [
        "### Code content\n",
        "\n",
        "Use the highest level API that gets the job done (unless the goal is to demonstrate the low level API).\n",
        "\n",
        "Use `keras.Sequential` \u003e keras functional api \u003e keras model subclassing \u003e ...\n",
        "\n",
        "Use  `model.fit` \u003e `model.train_on_batch` \u003e manual `GradientTapes`.\n",
        "\n",
        "Use eager-style code.\n",
        "\n",
        "Use `tensorflow_datasets` and `tf.data` where possible.\n",
        "\n",
        "Avoid `compat.v1`.\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "78HBT9cQXJko"
      },
      "source": [
        "### Text\n",
        "\n",
        "* Use an imperative style. \"Run a batch of images through the model.\"\n",
        "\n",
        "* Use sentence case in titles/headings. \n",
        "\n",
        "* Use short titles/headings: \"Download the data\", \"Build the Model\", \"Train the model\".\n"
      ]
    }
  ],
  "metadata": {
    "colab": {
      "collapsed_sections": [
        "Tce3stUlHN0L"
      ],
      "name": "notebook.ipynb",
      "toc_visible": true
    },
    "kernelspec": {
      "display_name": "Python 3",
      "name": "python3"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 0
}
